home *** CD-ROM | disk | FTP | other *** search
/ Mission 3 / Mission 3.zip / Mission 3.iso / texte / 7up_pd / menuikey.c < prev    next >
Text File  |  1998-10-29  |  14KB  |  583 lines

  1. /* Tastaturbedienung des Menüs */
  2. /*****************************************************************************
  3. *
  4. *                                              7UP
  5. *                                      Modul: MENUIKEY.C
  6. *                                     (c) by TheoSoft '90
  7. *
  8. *****************************************************************************/
  9. #include <portab.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <ctype.h>
  14. #if GEMDOS
  15. #include <tos.h>
  16. #include <ext.h>
  17. #else
  18. extern unsigned char b_keycod[];
  19. #endif
  20. #include <aes.h>
  21.  
  22. #include "7up.h"
  23. #include "windows.h"
  24.  
  25. #if GEMDOS
  26. #define  F1        0x3b
  27. #define  F10    0x44
  28. #define  F11    0x54
  29. #define  F20    0x5d
  30.  
  31. #define  K_CAPS    0x10
  32. #define  K_SHIFT    0x03
  33. #define  K_SCAN    0x8000
  34. #define  K_NUM        0x4000
  35. #else
  36. #define  F1        0x68
  37. #define  F10    0x71
  38. #define  F11    0x72
  39. #define  F20    0x7B
  40. #endif
  41.  
  42. #define FLAGS15 0x8000
  43.  
  44. int SysKey=FALSE;
  45.  
  46. #if GEMDOS
  47. static KEYTAB *pkeytbl=NULL;
  48. #endif
  49.  
  50. extern int ydesk;
  51.  
  52. char *split_fname(char *filename);
  53.  
  54. static int test_entry(char *str, int kstate, int key, int ob_flags)
  55. {
  56.     char *pchar, vchr;
  57.     int ret=0,zahl;
  58.  
  59.     pchar = str;
  60.     while(*pchar)
  61.         pchar++;
  62.     while(*--pchar == ' ')
  63.         ;
  64.     vchr=__tolower(*pchar);
  65.  
  66.     if(vchr == __tolower((char)key) && !(key & 0x8000))/* 0x8000 = Scancode */
  67.     {
  68.         pchar-=2;
  69.         if((*pchar==1    && *(pchar+1)=='^' && kstate==(K_CTRL|K_LSHIFT)) ||
  70.             (*pchar==1    && *(pchar+1)== 7  && kstate==(K_ALT |K_LSHIFT)))
  71.             return(TRUE);
  72.  
  73.         if((*pchar==' ' && *(pchar+1)=='^' && kstate==K_CTRL) ||
  74.             (*pchar==' ' && *(pchar+1)== 7  && kstate==K_ALT))
  75.             return(TRUE);
  76.  
  77.         if(((*pchar==' ' && *(pchar+1)=='^' && kstate==(K_CTRL|K_LSHIFT)) ||
  78.              (*pchar==' ' && *(pchar+1)== 7  && kstate==(K_ALT |K_LSHIFT))) &&
  79.             (ob_flags & FLAGS15))
  80.             return(TRUE);
  81.     }
  82.     if(key & 0x8000) /* Funktionstaste */
  83.     {
  84.         if(*pchar >= '0' && *pchar <= '9')
  85.         {
  86.             zahl=*pchar-'0';
  87.             pchar--;
  88.             if(*pchar >= '0' && *pchar <= '9')
  89.             {
  90.                 zahl+=(*pchar-'0')*10;
  91.                 pchar--;
  92.             }
  93.             if(*pchar == 'F')
  94.             {
  95.                key&=0x00FF;
  96.                 if(*(pchar-1)=='⇧') /* z.B.: ⇧F4 */
  97.                     zahl+=10;
  98.                 if((zahl>=1) && (zahl<=10))
  99.                     if(zahl==(key-F1+1))
  100.                         ret=1;
  101.                 if((zahl>=11) && (zahl<=20))
  102.                     if(zahl==(key-F11+11))
  103.                         ret=1;
  104.             }
  105.       }
  106.         if((kstate &  K_ALT) && (*(pchar-1) != 7))  /*7Fx*/
  107.             ret=0;
  108.         if((kstate & K_CTRL) && (*(pchar-1) != '^'))/*^Fx*/
  109.             ret=0;
  110.    }
  111. /*
  112.     if(key & 0x8000) /* Funktionstaste */
  113.     {
  114.         if(*pchar =='\'' && (kstate & (K_CTRL|K_ALT))==0)
  115.         {
  116.             pchar--;
  117.             vchr=__tolower(*pchar);
  118.             if(vchr==key && *(pchar-1)=='\'')
  119.                 ret=1;
  120.         }
  121.         else
  122.         {
  123.             if(*pchar >= '0' && *pchar <= '9')
  124.             {
  125.                 zahl=*pchar-'0';
  126.                 pchar--;
  127.                 if(*pchar >= '0' && *pchar <= '9')
  128.                 {
  129.                     zahl+=(*pchar-'0')*10;
  130.                     pchar--;
  131.                 }
  132.                 if(*pchar == 'F')
  133.                 {
  134.                    key&=0x00FF;
  135.                     if(*(pchar-1)=='⇧') /* z.B.: ⇧F4 */
  136.                         zahl+=10;
  137.                     if((zahl>=1) && (zahl<=10))
  138.                         if(zahl==(key-F1+1))
  139.                             ret=1;
  140.                     if((zahl>=11) && (zahl<=20))
  141.                         if(zahl==(key-F11+11))
  142.                             ret=1;
  143.                 }
  144.             }
  145.       }
  146.    }
  147. */
  148.     return(ret);
  149. }
  150.  
  151. static int _menu_ikey(OBJECT *m_tree, int kstate, int key, int *menu, int *item)
  152. {
  153.     int do_quit=0, desk=1;
  154.     register int m_title, c_title, m_entry, c_entry;
  155.     int msgbuf[8];
  156.    WINDOW *wp;
  157.    
  158.     if(!(kstate & (K_CTRL|K_ALT)) || __tolower((char)key)=='y')
  159.         return(FALSE);         /* keine Sondertaste > kein Shortcut */
  160.  
  161.     msgbuf[4]=0;
  162.  
  163.     m_title=(m_tree+m_tree->ob_head)->ob_head;
  164.     c_title=(m_tree+m_title)->ob_head;
  165.     m_entry=(m_tree+m_tree->ob_tail)->ob_head;
  166.     c_entry=(m_tree+m_entry)->ob_head;
  167.     while(!do_quit)
  168.     {
  169.         if(((m_tree +c_title)->ob_state & DISABLED) == 0)
  170.         {
  171.             while(!do_quit && c_entry != m_entry && c_entry != -1)
  172.             {
  173.                 if( ((m_tree+c_entry)->ob_type != G_USERDEF) &&
  174.                     
  175.                     /* MT 16.4.95 disablete Menüpunkte müssen auch durchsucht werden */
  176.                     /*(((m_tree+c_entry)->ob_state & DISABLED) == 0) &&*/
  177.                      
  178.                      ((m_tree+c_entry)->ob_type == G_STRING ||
  179.                       (m_tree+c_entry)->ob_type == G_BUTTON))
  180.                     do_quit=test_entry((char *)(m_tree+c_entry)->ob_spec.index,
  181.                                     kstate,key,(m_tree+c_entry)->ob_flags);
  182.                 if(do_quit)
  183.                 {
  184.                     if (((m_tree+c_entry)->ob_state & DISABLED) == 0)
  185.                     { 
  186.                         msgbuf[0]=MN_SELECTED;
  187. #if GEMDOS
  188.                         msgbuf[1]=_GemParBlk.global[2];
  189. #else
  190.                         msgbuf[1]=gb.gb_pglobal[2];
  191. #endif
  192.                         msgbuf[2]=0;
  193.                         *menu=msgbuf[3]=c_title;
  194.                        *item=msgbuf[4]=c_entry;
  195. #if MiNT
  196.                         wind_update(BEG_UPDATE);
  197.                         wind_update(END_UPDATE);
  198. #endif
  199.                         graf_mouse(M_ON, NULL);/* nur bei eventgesteuerter Maus */
  200.                         menu_tnormal(m_tree,c_title,0);
  201.                         wp=Wgettop();
  202.                         toolbar_tnormal(wp,wp?wp->toolbar:NULL,c_entry,0);
  203. /* alte Version
  204.                         appl_write(msgbuf[1],16,msgbuf);
  205. */
  206.                     }
  207.                     else /* wenn disabled, anderen Returncode verwenden */
  208.                     {
  209.                         msgbuf[4]=-1; /* gefunden, aber disabled */
  210.                     }
  211.  
  212.                 }
  213.                 c_entry=(m_tree+c_entry)->ob_next;
  214.                 if(desk)
  215.                 {
  216.                     c_entry=m_entry;
  217.                     desk=0;
  218.                 }
  219.             }
  220.         }
  221.         c_title=(m_tree+c_title)->ob_next;
  222.         m_entry=(m_tree+m_entry)->ob_next;
  223.         c_entry=(m_tree+m_entry)->ob_head;
  224.         if(c_title==m_title)
  225.         {
  226.             do_quit=1;
  227.         }
  228.     }
  229.     return(msgbuf[4]);
  230. }
  231.  
  232. static int test_SysKeyentry(char *str, char chr1, char chr2)
  233. {
  234.     char *cp;
  235.     
  236.     if((cp=strchr(str,'^'))!=NULL && (chr1==*(cp+1)) && (chr2==*(cp+2)))
  237.         return(TRUE);
  238.     return(FALSE);
  239. }
  240.  
  241. static int _menu_SysKey(OBJECT *m_tree, int kstate, int key, int *menu, int *item)
  242. {
  243.     char chr1, chr2;
  244.     int i, do_quit=0, desk=1;
  245.     register int m_title, c_title, m_entry, c_entry;
  246.     int msgbuf[8];
  247.     WINDOW *wp;
  248.  
  249.     if(!(kstate & K_CTRL)|| /* kein ^      */
  250.         (kstate & K_ALT) || /* Alt          */
  251.         (key==0x0408)         || /* ^Backspace */
  252.         (key==0x047F)         || /* ^Delete    */
  253.         ((char)key=='y')    || /* ^Y            */
  254.         ((char)key=='e')    || /* ^E            */
  255.         ((char)key=='a') || /* ^A            */
  256.         ((char)key=='Y')    || /* ^Y            */
  257.         ((char)key=='E')    || /* ^E            */
  258.         ((char)key=='A'))    /* ^A            */
  259.         return(FALSE); /* raus bei nicht Control oder Alt */
  260.  
  261.     msgbuf[3]=msgbuf[4]=0;
  262.    
  263.    chr1=__toupper((char)key);
  264.    
  265.     for(i=ROOT+3; m_tree[i].ob_type==G_TITLE; i++)
  266.     {
  267.         if(!(m_tree[i].ob_state & DISABLED) && chr1==__toupper(*((char *)m_tree[i].ob_spec.index+1L)))
  268.         {
  269.               menu_tnormal(m_tree,msgbuf[3]=i,FALSE);
  270.  
  271.             wind_update(BEG_UPDATE);             /* Keine Menüaktionen */
  272. /*
  273.            m_tree[WINNEW-1].ob_flags|=FLAGS15; /* kein Windial!!! */
  274.            m_tree[WINNEW-1].ob_next=-1;
  275.            m_tree[WINNEW-1].ob_head=1;
  276.            m_tree[WINNEW-1].ob_tail=WINQUIT-WINNEW+1;
  277.            m_tree[WINNEW-1].ob_y=ydesk;
  278.          for(i=WINNEW; i<WINQUIT; i++)
  279.                m_tree[i].ob_next=i-WINNEW+2;
  280.            m_tree[WINQUIT].ob_next=0;
  281.            m_tree[WINQUIT].ob_head=-1;
  282.            m_tree[WINQUIT].ob_tail=-1;
  283.            m_tree[WINQUIT ].ob_flags|=LASTOB; /* */            
  284.          form_exopen(&m_tree[WINNEW-1],0);
  285. */
  286.             key=evnt_keybd();            /* zweiten Tastendruck abwarten */
  287. /*
  288.          form_exclose(&m_tree[WINNEW-1],-1,0);
  289.            m_tree[WINNEW-1].ob_flags&=~FLAGS15; 
  290.            m_tree[WINNEW-1].ob_next=39;
  291.            m_tree[WINNEW-1].ob_head=WINNEW;
  292.            m_tree[WINNEW-1].ob_tail=WINQUIT;
  293.            m_tree[WINNEW-1].ob_y=0;
  294.          for(i=WINNEW; i<WINQUIT; i++)
  295.                m_tree[i].ob_next=i+1;
  296.            m_tree[WINQUIT].ob_next=21;
  297.            m_tree[WINQUIT].ob_head=-1;
  298.            m_tree[WINQUIT].ob_tail=-1;
  299.            m_tree[WINQUIT ].ob_flags&=~LASTOB; /* */
  300. */
  301.             wind_update(END_UPDATE);
  302.  
  303.          MapKey(&kstate,&key);
  304.          kstate=0;
  305.             chr2=__toupper((char)key);
  306.  
  307.             m_title=(m_tree+m_tree->ob_head)->ob_head;
  308.             c_title=(m_tree+m_title)->ob_head;
  309.             m_entry=(m_tree+m_tree->ob_tail)->ob_head;
  310.             c_entry=(m_tree+m_entry)->ob_head;
  311.             while(!do_quit)
  312.             {
  313.                 if(((m_tree +c_title)->ob_state & DISABLED) == 0)
  314.                 {
  315.                     while(!do_quit && c_entry != m_entry && c_entry != -1)
  316.                     {
  317.                         if( ((m_tree+c_entry)->ob_type != G_USERDEF) &&
  318.                             (((m_tree+c_entry)->ob_state & DISABLED) == 0) &&
  319.                              ((m_tree+c_entry)->ob_type == G_STRING ||
  320.                               (m_tree+c_entry)->ob_type == G_BUTTON))
  321.                             do_quit=test_SysKeyentry((char *)(m_tree+c_entry)->ob_spec.index,chr1,chr2);
  322.                         if(do_quit)
  323.                         {
  324.                             msgbuf[0]=MN_SELECTED;
  325. #if GEMDOS
  326.                             msgbuf[1]=_GemParBlk.global[2];
  327. #else
  328.                             msgbuf[1]=gb.gb_pglobal[2];
  329. #endif
  330.                             msgbuf[2]=0;
  331.                             *menu=msgbuf[3]=c_title;
  332.                            *item=msgbuf[4]=c_entry;
  333.                             graf_mouse(M_ON, NULL);/* nur bei eventgesteuerter Maus */
  334.                             wp=Wgettop();
  335.                             toolbar_tnormal(wp,wp?wp->toolbar:NULL,c_entry,0);
  336. /*
  337.                             appl_write(msgbuf[1],16,msgbuf);
  338. */
  339.                         }
  340.                         c_entry=(m_tree+c_entry)->ob_next;
  341.                         if(desk)
  342.                         {
  343.                             c_entry=m_entry;
  344.                             desk=0;
  345.                         }
  346.                     }
  347.                 }
  348.                 c_title=(m_tree+c_title)->ob_next;
  349.                 m_entry=(m_tree+m_entry)->ob_next;
  350.                 c_entry=(m_tree+m_entry)->ob_head;
  351.                 if(c_title==m_title)
  352.                 {
  353.                     do_quit=1;
  354.                 }
  355.             }
  356.         }
  357.     }
  358.    if(msgbuf[3] && !msgbuf[4]) /* zurücksetzen, weil falsch */
  359.         menu_tnormal(m_tree,msgbuf[3],TRUE);
  360.     return(msgbuf[4]);
  361. }
  362.  
  363. int menu_ikey(OBJECT *m_tree, int kstate, int key, int *menu, int *item)
  364. {
  365.     if(SysKey)
  366.         return(_menu_SysKey(m_tree, kstate, key, menu, item));
  367.     else
  368.         return(_menu_ikey(m_tree, kstate, key, menu, item));
  369. }
  370.  
  371. void _loadmenu(char *filename)
  372. {
  373.     FILE *fp;
  374.     char *cp;
  375.     
  376.     extern char iostring[];
  377.     extern OBJECT *winmenu,*menueditor;
  378.         
  379.     if((fp=fopen(filename,"r"))!=NULL)
  380.     {
  381.         form_write(menueditor,MENUMFILE,split_fname(filename),FALSE);
  382.         wind_update(BEG_UPDATE);
  383.       graf_mouse(BUSY_BEE,NULL);
  384.         SysKey=FALSE; /* erstmal zurücksetzen auf Standard */
  385.         while(fgets(iostring,80,fp)!=NULL)
  386.         {
  387.             if(*iostring!='#' && *iostring!='-')
  388.             {
  389.                 if(*iostring=='%')
  390.                 {
  391.                     if(!strncmp(iostring,"%SysKey",7))
  392.                         SysKey=TRUE;
  393.                 }
  394.                 else
  395.                 {
  396.                     if(iostring[strlen(iostring)-1]=='\n')
  397.                         iostring[strlen(iostring)-1]=0;
  398.                     if((cp=strchr(iostring,',')) && (strlen(cp+1)>0)) /* Komma drin? */
  399.                     {
  400.                         *cp=0;
  401.                         menu_text(winmenu,atoi(iostring),cp+1);
  402.                     }
  403.                 }
  404.             }
  405.         }
  406.       graf_mouse(ARROW,NULL);
  407.         wind_update(END_UPDATE);
  408.         fclose(fp);
  409.     }
  410. }
  411.  
  412. static void __savemenu(OBJECT *m_tree, FILE *fp)
  413. {
  414.     int do_quit=0, desk=1;
  415.     int m_title, c_title, m_entry, c_entry;
  416.    char menustr[40];
  417.  
  418.    fprintf(fp,"###############################\n");
  419.    fprintf(fp,"# 7UP 2.3 Menüshortcuts\n");
  420.    fprintf(fp,"###############################\n");
  421.     if(SysKey)
  422.        fprintf(fp,"%SysKey\n");
  423.     m_title=(m_tree+m_tree->ob_head)->ob_head;
  424.     c_title=(m_tree+m_title)->ob_head;
  425.     m_entry=(m_tree+m_tree->ob_tail)->ob_head;
  426.     c_entry=(m_tree+m_entry)->ob_head;
  427.     while(!do_quit)
  428.     {
  429.       fprintf(fp,"#==============================\n");
  430.         sprintf(menustr,"#    %s\n",(char *)m_tree[c_title].ob_spec.index);
  431.         fprintf(fp,strupr(menustr));
  432.         while(c_entry != m_entry && c_entry != -1)
  433.         {
  434.             /* Trennlinie ist überflüssig */
  435.             if(! (char *)m_tree[c_entry].ob_spec.index ||
  436.                !*(char *)m_tree[c_entry].ob_spec.index ||
  437.                 *(char *)m_tree[c_entry].ob_spec.index == '-') /* Let 'em Fly am Werk */
  438.                 fprintf(fp,"#---\n");
  439.             else
  440.              if(!(c_entry>=WINDAT1 && c_entry<=WINDAT7)) /* diese benötigen wir nicht */
  441.                     fprintf(fp,"%003d,%s\n",c_entry, (char *)m_tree[c_entry].ob_spec.index);
  442.             
  443.             c_entry=(m_tree+c_entry)->ob_next;
  444.             if(desk)
  445.             {
  446.                 c_entry=m_entry;
  447.                 desk=0;
  448.             }
  449.         }
  450.         c_title=(m_tree+c_title)->ob_next;
  451.         m_entry=(m_tree+m_entry)->ob_next;
  452.         c_entry=(m_tree+m_entry)->ob_head;
  453.         if(c_title==m_title)
  454.         {
  455.             do_quit=1;
  456.         }
  457.     }
  458. }
  459.  
  460. void _savemenu(char *filename)
  461. {
  462.     FILE *fp;
  463.     if((fp=fopen(filename,"w"))!=NULL)
  464.     {
  465.         wind_update(BEG_UPDATE);
  466.       graf_mouse(BUSY_BEE,NULL);
  467.       __savemenu(winmenu,fp);
  468.       graf_mouse(ARROW,NULL);
  469.         wind_update(END_UPDATE);
  470.         fclose(fp);
  471.     }    
  472. }
  473.  
  474. void loadmenu(char *filename)
  475. {
  476.     char *cp,pathname[PATH_MAX];
  477.     
  478.    search_env(pathname,filename,FALSE); /* READ */
  479.     _loadmenu(pathname);
  480. }
  481.  
  482. static void sonderzeichen(int *kstate, int *key)
  483. {  /* Capslock ausmaskiert */
  484.     extern int eszet,komma;
  485.     
  486.    switch(*key)
  487.    {
  488.       case 0x402E: /* Zehnerblockpunkt */
  489.          if(komma)
  490.             *key=',';
  491.          break;
  492.       case 'ß':
  493.             if(eszet)
  494.                 *key='β';
  495.             break;
  496.       case 0x0A9A:
  497.          *kstate=0;
  498.             *key='\\';
  499.          break;
  500.       case 0x0881:
  501.       case 0x089A:/* caps */
  502.          *kstate=0;
  503.             *key='@';
  504.          break;
  505.       case 0x0A99:
  506.          *kstate=0;
  507.             *key='{';
  508.          break;
  509.       case 0x0A8E:
  510.          *kstate=0;
  511.             *key='}';
  512.          break;
  513.       case 0x0894:
  514.       case 0x0899:/* caps */
  515.          *kstate=0;
  516.             *key='[';
  517.          break;
  518.       case 0x0884:
  519.       case 0x088E:/* caps */
  520.          *kstate=0;
  521.             *key=']';
  522.          break;
  523.    }
  524. }
  525.  
  526. int MapKey(int *kstate, int *key)
  527. {
  528.     register int ks,sc,ret;
  529.  
  530.     if(!pkeytbl)
  531.         pkeytbl=Keytbl(-1L,-1L,-1L);
  532.  
  533.     sc=((*key)>>8)&0xFF;
  534.  
  535.     ks=(int)Kbshift(-1);
  536. /*
  537.     ks=*kstate; /* wg. Macrorecorder 16.4.94. Denkste, kein CAPS!!! */
  538. */    
  539.    /* ALT 1 - ALT ß -> runterrechnen auf 2 - 13 */
  540.    if((ks&K_ALT) && (sc>=0x78) && (sc<=0x83))
  541.        sc-=0x76;
  542.  
  543.     if((ks&K_CAPS) && !(ks&K_SHIFT))
  544.         ret=pkeytbl->capslock[sc];
  545.     else
  546.     {
  547.         if(ks&K_SHIFT)
  548.       {
  549.          if (( sc >= 0x54 ) && ( sc <= 0x5d ))
  550.             ret= pkeytbl->shift[sc - 0x19];
  551.          else if (( sc == 0x47 ) || ( sc == 0x48 ) || ( sc == 0x4b ) ||
  552.                ( sc == 0x4d ) || ( sc == 0x50 ) || ( sc == 0x52 ))
  553.                   /* Ins, Clr, Cursor - fehlt im Profibuch */
  554.             ret = 0;
  555.          else
  556.             ret = pkeytbl->shift[sc];
  557.       }
  558.       else
  559.          ret = pkeytbl->unshift[sc];
  560.     }
  561.     if(!ret)
  562.         ret=sc|K_SCAN;
  563.     else  /* Ziffernblock markieren */
  564.         if((sc==0x4A) || (sc==0x4E) || ((sc>=0x63) && (sc<=0x72)))
  565.             ret|=K_NUM;
  566.  
  567.     if(ks & K_RSHIFT)
  568.     {
  569.         ks &= ~K_RSHIFT;
  570.         ks |=  K_LSHIFT;
  571.     }
  572.  
  573.    ks&=~K_CAPS; /* CAPSLOCK ausblenden */
  574.  
  575.     *kstate=ks;
  576.     *key=((ks<<8)|ret);
  577.  
  578.    sonderzeichen(kstate,key);
  579.  
  580.     return(*key);
  581. }
  582.  
  583.